<template>
  <div class="components-container">
    <div class="header-form">
      <div class="layui-inline">
        <label class="layui-form-label">状态</label>
        <div class="layui-inline" style="margin-top:-6px">
          <el-radio-group v-model="selectDataEixend.StatusEquals" @change="getData">
            <el-radio-button v-for="item in statusOptions" :key="item.Value" :label="item.Value" class="radio">
              {{item.Text}}</el-radio-button>
          </el-radio-group>
        </div>
      </div>
    </div>
    <div class="header-form">
      <div class="layui-inline">
        <label class="layui-form-label">逝者姓名</label>
        <div class="layui-inline">
          <el-input v-model="selectDataEixend.DeadNameLike" placeholder="请输入逝者姓名" @keydown.enter.native='getData'></el-input>
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">证件号码</label>
        <div class="layui-inline">
          <el-input v-model="selectDataEixend.CardNoLike" placeholder="请输入证件号码"  @keydown.enter.native='getData'></el-input>
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">户籍地址</label>
        <div class="layui-inline">
          <el-input style="width:220px;" v-model="selectDataEixend.DetailAddressLike" placeholder="请输入户籍地址"  @keydown.enter.native='getData'></el-input>
        </div>
      </div>
      <el-button type="primary" @click="getData" :loading="this.$store.state.isloading">搜索</el-button>
      <el-button @click="btnRepeat">重置</el-button>
    </div>
    <div style="margin-top:10px;">
      <ul class="toolList">
        <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon"
          @click="operate(item.BTNVALUE)">
          <el-button type="primary" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
        </li>
      </ul>
    </div>
    <dataTable :headList="headList" :dataList="dataList" :hiddenWarn="hiddenWarn" :clounmnames="clounmnames" :pageOrder="pageOrder" @pageChange="pageChange" @selectRow="selectRow"></dataTable>
    <mainModel ref="dialog"></mainModel>
    <Appendixlists ref="dialogs"></Appendixlists>
  </div>
</template>
<style rel="stylesheet/scss" lang="scss" scoped>
  @import "src/styles/common.scss";

  .el-button+.el-button {
    margin-left: 0;
  }

  .longtext {
    width: 480px;
  }

  .longertext {
    width: 770px;
  }

  .sweet-btn {
    margin-top: 20px;
  }

  .radio {
    margin-top: 9px;
  }

</style>
<script>
  import dataTable from "@/components/Table/DataTable";
  import apiBase from "@/api/apiBase.js";
  import {
    formatDate,
    timeStringToDate
  } from "@/utils/date.js";
  import {
    manage
  } from "@/mixins/managePage.js";
  import mainModel from "./seecQueryMain.vue";
  import Appendixlists from "../jointPlatform/Appendixlists";
  const defaultstatus = 'A' // 预约中
  export default {
    name: "seecQuery",
    mixins: [manage],
    data() {
      return {
        selectDataEixend: {
          DetailAddressLike: null,
          DeadNameLike: null,
          CardNoLike: null,
          StatusEquals: defaultstatus
        },
        statusOptions: [],
        hiddenWarn: true,
        clounmnames: '冻结状态',//决定冻结这一列的表头名字
      };
    },
    methods: {
      //
      getinitData() {
        // 获取状态
        apiBase.DoService({},
          apiBase.getApiAdress().Reserve.GetReserveStatus,
          res => {
            this.statusOptions = res.data.content;
          }
        );
      },
      //获取火化登记数据
      getData() {
        let datas = {
          CardNoLike: this.selectDataEixend.CardNoLike,
          DeadNameLike: this.selectDataEixend.DeadNameLike,
          DetailAddressLike: this.selectDataEixend.DetailAddressLike,
          StatusEquals: this.selectDataEixend.StatusEquals,
        };
        let data = {
          PageIndex: this.pageOrder.currentPage,
          PageSize: this.pageOrder.pageSize,
          OrderBy: this.pageOrder.orderType,
          OrderByType: this.pageOrder.orderSort,
          Data: datas
        };
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Reserve.QueryReserveJoint,
          res => {
            this.dataList = res.data.content.OutData;
            this.pageOrder.totalNum = res.data.content.RecordCount;
          }
        );
      },
      //获取表头
      getColumns() {
        let data = {};
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Column.GetSeecQueryColumns,
          res => {
            this.headList = res.data.content;
          }
        );
      },
      btnShow(btn) {
        switch (btn) {
          case "取消":
            if (this.currentRow) {
              if (this.currentRow.PRPSTATUS === defaultstatus) {
                return true
              }
            }
            break;
          case "回退预约":
            if (this.currentRow) {
              if (this.currentRow.PRPSTATUS === 'C') {
                return true
              }
            }
            break;
            case "联办附件":
              if(this.currentRow) {
                return true;
              }
              break;
          default:
        }
      },
      //功能操作
      operate(order) {
        this.order = order;
        this.dataRepeat();
        switch (this.order) {
          case "取消":
            this.cancel(this.currentRow.PRPID)
            break;
          case "回退预约":
            this.ModifyReserve(this.currentRow.PRPID)
            break;
          case "详情":
            this.$refs.dialog.open(order, this.currentRow.PRPID)
            break;
          case "联办附件":
            this.$refs.dialogs.operate('附件上传', this.currentRow.PRPID)
            break;
          default:
        }
      },
      // 取消
      cancel(id) {
        this.$confirm('此操作将取消此联办数据', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          apiBase.DoService(
            {
                PRPID:id,
            },
            apiBase.getApiAdress().Reserve.ModifyCancelReserve,
            res => {
              this.$message({
                type: 'success',
                message: '取消成功!'
              });
              this.getData()
            }
          );
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已放弃取消'
          });
        });
      },
      // 状态转预约中
      ModifyReserve(id) {
        this.$confirm('此操作将把该数据状态转为预约中', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          apiBase.DoService(
            {
                PRPID:id,
            },
            apiBase.getApiAdress().Reserve.ModifyReserve,
            res => {
              this.$message({
                type: 'success',
                message: '成功!'
              });
              this.getData()
            }
          );
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已放弃'
          });
        });
      },
      //提交
      submit() {},

      //查询条件重置
      btnRepeat() {
        this.selectDataEixend.CardNoLike = null;
        this.selectDataEixend.DeadNameLike = null;
        this.selectDataEixend.DetailAddressLike = null;
        this.selectDataEixend.StatusEquals = defaultstatus;
        this.getData();
      },
      //数据重置
      dataRepeat() {
        //   Object.assign(this.$data.regData, this.$options.data().regData);
      },
    },
    mounted() {},
    components: {
      dataTable,
      mainModel,
      Appendixlists
    },
    activated() {
      this.getData();
    },
    created() {
      this.getColumns();
      this.getinitData();
    },
  };

</script>
